package com.demo.security.package1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LiYuhang
 * @version 0.1
 * @application 发布和初始化导致线程安全问题
 * @Date 2020/12/16 16:52
 */

public class WrongInit {
    private Map<Integer, String> students;
    public WrongInit() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                students = new HashMap<>();
                students.put(1, "王小美");
                students.put(2, "钱二宝");
                students.put(3, "周三");
                students.put(4, "赵四");
            }
        }).start();
    }
    public Map<Integer, String> getStudents() {
        return students;
    }
    public static void main(String[] args) throws InterruptedException {
        WrongInit multiThreadsError6 = new WrongInit();
        System.out.println(multiThreadsError6.getStudents().get(1));

    }
}
